﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class CmsDataRelationCls
    {
        public string RelationDataId;
        public string DataId;
        public string DataAlias;
        public string Subject;
        public string AttachDoc;
    }

    public class CmsDataRelationParser
    {
        public static CmsDataRelationCls CreateInstance()
        {
            //tao 1 class trang....
            CmsDataRelationCls oCmsDataRelationCls = new CmsDataRelationCls();
            return oCmsDataRelationCls;
        }

        public static CmsDataRelationCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            CmsDataRelationCls oCmsDataRelationCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oCmsDataRelationCls;
        }


        public static CmsDataRelationCls ParseFromDataRow(DataRow dr)
        {
            CmsDataRelationCls oCmsDataRelationCls = new CmsDataRelationCls();
            oCmsDataRelationCls.RelationDataId = XmlUtility.GetString(dr, "RelationDataId", true);
            oCmsDataRelationCls.DataId = XmlUtility.GetString(dr, "DataId", true);
            oCmsDataRelationCls.DataAlias = XmlUtility.GetString(dr, "DataAlias", true);
            oCmsDataRelationCls.Subject = XmlUtility.GetString(dr, "Subject", true);
            oCmsDataRelationCls.AttachDoc = XmlUtility.GetString(dr, "AttachDoc", true);

            return oCmsDataRelationCls;
        }

        public static CmsDataRelationCls[] ParseFromDataTable(DataTable dtTable)
        {
            CmsDataRelationCls[] CmsDataRelations = new CmsDataRelationCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                CmsDataRelations[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return CmsDataRelations;
        }

        public static CmsDataRelationCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new CmsDataRelationCls[0];
            }
            CmsDataRelationCls[] CmsDataRelations = new CmsDataRelationCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                CmsDataRelations[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return CmsDataRelations;
        }

       
            //Environments.HttpDataRoot(SiteId) 
        //    return HttpDataRoot + "/DocumentArchives/" + AssetCode + "/ArchiveDoc/Archive/" + AttachDoc;
       
    }
}
